#include "loader.h"

TString getMCSampleXML() {
   TString filename = "xml/rel16/mc_slim.xml";
   return filename;
}

TString getDataSampleXML() {
   //TString filename = "xml/rel16/data_noslim.xml";       // files on NFS
   TString filename = "xml/rel16/data_noslim_local.xml"; // files on local disk
   //TString filename = "xml/rel16/data_noslim_rfio.xml";  // files on grid storage access via RFIO
   return filename;
}

TChain * getOneDataChain(TString flavor, TString name, TString modification){

   vector<TString> filenames ;
   
   TString filename = getDataSampleXML(); 

   xmlfile  = new XMLConfig();
 
   xmlfile->readFile(filename,name,modification, &filenames);

   TChain * chain = new TChain("tree");

   for(size_t i=0; i<filenames.size(); i++){
       chain->AddFile(filenames[i]);
   }

   return chain;
}

TChain * getOneMCChain(TString flavor, TString name, TString modification){
 
   vector<TString> filenames ;

   TString filename = getMCSampleXML();

   xmlfile  = new XMLConfig();

   xmlfile->readFile(filename,name,modification, &filenames);

   TChain * chain = new TChain("tree");

   for(size_t i=0; i<filenames.size(); i++){
       chain->AddFile(filenames[i]);
   }

   return chain;
}

TFileCollection *getOneDataCollection(TString flavor, TString name, TString modification) {

   vector<TString> filenames ;

   TString filename = getDataSampleXML(); 

   xmlfile  = new XMLConfig();
 
   xmlfile->readFile(filename, name, modification, &filenames);

   TFileCollection *c = new TFileCollection();

   for(size_t i=0; i<filenames.size(); i++){
       c->Add(new TFileInfo(filenames[i]));
   }

   return c;
}

TFileCollection *getOneMCCollection(TString flavor, TString name, TString modification) {

   vector<TString> filenames ;

   TString filename = getMCSampleXML(); 

   xmlfile  = new XMLConfig();
 
   xmlfile->readFile(filename, name, modification, &filenames);

   TFileCollection *c = new TFileCollection();

   for(size_t i=0; i<filenames.size(); i++){
       c->Add(new TFileInfo(filenames[i]));
   }

   return c;
}

TChain * getMCChain(TString flavor, TString modification){

   TChain * chain = new TChain("tree");
   chain->Add(getOneMCChain(flavor, "ttbar", modification));
   chain->Add(getOneMCChain(flavor, "singletop", modification));
   chain->Add(getOneMCChain(flavor, "wjets", modification));
   chain->Add(getOneMCChain(flavor, "zjets", modification));
   chain->Add(getOneMCChain(flavor, "diboson", modification));
   chain->Add(getOneMCChain(flavor, "qcd", modification));
   chain->Add(getOneMCChain(flavor, "qcdbb", modification));
   
   return chain;
}

TChain * getDataChain(TString flavor, TString modification){

   /*
   TChain * chain = new TChain("tree");
   chain->Add(getOneDataChain(flavor, "periodA", modification));
   chain->Add(getOneDataChain(flavor, "periodB", modification));
   chain->Add(getOneDataChain(flavor, "periodC", modification));
   chain->Add(getOneDataChain(flavor, "periodD", modification));
   chain->Add(getOneDataChain(flavor, "periodE", modification));
   chain->Add(getOneDataChain(flavor, "periodF", modification));
   chain->Add(getOneDataChain(flavor, "periodG", modification));
   chain->Add(getOneDataChain(flavor, "periodH", modification));
   chain->Add(getOneDataChain(flavor, "periodI", modification));
   */
   
   TChain *chain = getOneDataChain(flavor, "2010", modification);

   return chain;
}
